using UnityEngine;

namespace Client.Base
{
    public abstract class CSharpSingleton<T> :BaseLogic   where T : class, new()
    {
        static private T instance;
        static public T Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new T();
                }
                return instance;
            }
        }
    }

    public abstract class UnitySingleton<T>  : MonoBehaviour where T : Component
    {
        static private T instance;
        static public T Instance
        {
            get
            {
                if (instance == null)
                {
                    GameObject clone = new GameObject(typeof(T).Name);
                    instance = clone.AddComponent<T>();
                    GameObject.DontDestroyOnLoad(clone);
                }
                return instance;
            }
        }

        private void wake()
        {
            OnAwake();
        }

        protected abstract void OnAwake();
  
    }
}

